package Util;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

/**
 * Helper class for handling and reporting errors.
 * @author ARK
 * Date			Description
 * 04/08/2012	Created
 * */
public class ErrorHelper {
	
	// Set to true if you want user to know of any errors. Set to false for production use.
	public static boolean debug = true;
	
	/**
	 * Reports the given exception to the LOGCAT and prints the stack trace. Also
	 * alerts the user of the error through a Toast dialog.
	 * @param	activity	The activity instance associated with exception.
	 * @param	exception	The exception to report.
	 * */
	static public void reportError(Activity activity, Exception exception){
		String msg = exception.getMessage();
		Log.e(activity.getLocalClassName(), msg);
		exception.printStackTrace();
		if (debug) {
			Toast.makeText(activity.getApplicationContext(), msg, Toast.LENGTH_LONG);
		}
	}
	
	/**
	 * Reports the given exception to the LOGCAT and prints stack trace. Also
	 * alerts the user of error through Toast dialog.
	 * @param	classObj	The class containing the exception.
	 * @param	context		The context of the exception.
	 * @param	exception	The exception instance.
	 * */
	static public void reportError(Class<?> classObj, Context context, Exception exception){
		String msg = exception.getMessage();
		Log.e(classObj.getName(), msg);
		exception.printStackTrace();
		if (debug) {
			Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG);
		}
	}
	
	/**
	 * Reports the given exception to the LOGCAT and prints stack trace. Also
	 * alerts the user of error through Toast dialog.
	 * @param	msg			The {@link String} message to report.
	 * @param	context		The context of the exception.
	 * @param	exception	The exception instance.
	 * */
	static public void reportError(String msg, Context context, Exception exception) {
		Log.e(context.getPackageName(), msg);
		exception.printStackTrace();
		if (debug) {
			Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG);
		}
	}
}
